<template>
  <div class="enterprise">
    <div class="enterprise-table">
      <div class="enterprise-table-tools">
        <el-button type="primary" @click="addEnterprise">新增</el-button>
      </div>
      <div class="enterprise-table-list">
        <el-table :data="list" height="400">
          <el-table-column
            v-for="item in tableColumns"
            :key="item.prop"
            :prop="item.prop"
            :label="item.label"
          >
          </el-table-column>
        </el-table>
      </div>
    </div>
  </div>
</template>

<script setup>
import api from '@/http/index.js'
import { reactive, ref } from 'vue'
import { createUser } from '@/views/user/create/index.js'
import { createEnterprise } from './create/index.js'

let list = ref([])
const tableColumns = reactive([
  { prop: 'enterpriseId', label: '企业ID' },
  { prop: 'enterpriseName', label: '企业名称' },
  { prop: 'enterpriseAddress', label: '企业地址' },
  { prop: 'enterpriseCharter', label: '企业经营许可证' },
  { prop: 'enterpriseLogo', label: '企业Logo' },
  { prop: 'phonenumber', label: '电话' },
  { prop: 'email', label: '邮箱' },
  { prop: 'loginDate', label: '最后登录时间' },
  { prop: 'expireTime', label: '服务到期时间' },
])
const getList = async () => {
  const res = await api.enterprise.get()
  list.value = res.data.map((item) => ({
    ...item,
    ...(item?.user || {}),
  }))
}

getList()

const addEnterprise = () => {
  createUser({
    okText: '下一步',
  })
    .then((user) => {
      createEnterprise(user)
    })
    .catch(() => {})
}
</script>

<style lang="scss">
.enterprise {
  width: 100%;
  height: 100%;
  background-color: #fff;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 14px;
  &-table {
    &-tools {
      margin-bottom: 16px;
    }
  }
}
</style>
